﻿// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.AppliesToBehaviorDecisionTable
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 8E14765A-6610-409A-BA36-099A0642905D
// Assembly location: E:\git\ALLIDA\windll\infocard.exe

using System.ServiceModel;

namespace Microsoft.InfoCards
{
  internal static class AppliesToBehaviorDecisionTable
  {
    private static AppliesToBehaviorDecision[,] appliesToDecisionTable = new AppliesToBehaviorDecision[2, 3];

    static AppliesToBehaviorDecisionTable()
    {
      AppliesToBehaviorDecisionTable.appliesToDecisionTable[0, 0] = AppliesToBehaviorDecision.DoNotSend;
      AppliesToBehaviorDecisionTable.appliesToDecisionTable[1, 0] = AppliesToBehaviorDecision.FailMatch;
      AppliesToBehaviorDecisionTable.appliesToDecisionTable[0, 1] = AppliesToBehaviorDecision.DoNotSend;
      AppliesToBehaviorDecisionTable.appliesToDecisionTable[1, 1] = AppliesToBehaviorDecision.SendRPAppliesTo;
      AppliesToBehaviorDecisionTable.appliesToDecisionTable[0, 2] = AppliesToBehaviorDecision.SendCustomAppliesTo;
      AppliesToBehaviorDecisionTable.appliesToDecisionTable[1, 2] = AppliesToBehaviorDecision.SendRPAppliesTo;
    }

    private static AppliesToBehaviorDecision GetAppliesToBehaviorDecision(
      InfoCardPolicy policy,
      RequireAppliesToStatus requireAppliesTo,
      bool considerUnrecognizedElements)
    {
      int index = (EndpointAddress) null == policy.PolicyAppliesTo ? 0 : 1;
      if (considerUnrecognizedElements)
        index = policy.NonWhiteListElementsFound ? 1 : index;
      return AppliesToBehaviorDecisionTable.appliesToDecisionTable[index, (int) requireAppliesTo];
    }

    public static AppliesToBehaviorDecision GetAppliesToBehaviorDecisionForRst(
      InfoCardPolicy policy,
      RequireAppliesToStatus requireAppliesTo)
    {
      return AppliesToBehaviorDecisionTable.GetAppliesToBehaviorDecision(policy, requireAppliesTo, false);
    }

    public static AppliesToBehaviorDecision GetAppliesToBehaviorDecisionForPolicyMatch(
      InfoCardPolicy policy,
      RequireAppliesToStatus requireAppliesTo)
    {
      return AppliesToBehaviorDecisionTable.GetAppliesToBehaviorDecision(policy, requireAppliesTo, true);
    }
  }
}
